package com.example.leetcode.leetcode.hot100;


import java.util.*;

public class Solution17 {
    public static List<String> letterCombinations(String digits) {
        if(digits.length()==0){
            return new ArrayList<>();
        }
        List<String> result = new ArrayList<>(Collections.singletonList(""));
        for (int i = 0; i < digits.length(); i++) {
            List<String> tempList =new ArrayList<>();
            ListIterator<String> lit = result.listIterator();
            if(digits.charAt(i)=='2'){
                while (lit.hasNext()) {
                    String str = lit.next();
                    tempList.add(str + 'a');
                    tempList.add(str + 'b');
                    tempList.add(str + 'c');
                }

            }else if(digits.charAt(i)=='3'){
                while (lit.hasNext()) {
                    String str = lit.next();
                    tempList.add(str + 'd');
                    tempList.add(str + 'e');
                    tempList.add(str + 'f');
                }
            }else if(digits.charAt(i)=='4'){
                while (lit.hasNext()) {
                    String str = lit.next();
                    tempList.add(str + 'g');
                    tempList.add(str + 'h');
                    tempList.add(str + 'i');
                }
            }else if(digits.charAt(i)=='5'){
                while (lit.hasNext()) {
                    String str = lit.next();
                    tempList.add(str + 'j');
                    tempList.add(str + 'k');
                    tempList.add(str + 'l');
                }
            }else if(digits.charAt(i)=='6'){
                while (lit.hasNext()) {
                    String str = lit.next();
                    tempList.add(str + 'm');
                    tempList.add(str + 'n');
                    tempList.add(str + 'o');
                }
            }else if(digits.charAt(i)=='7'){

                while (lit.hasNext()) {
                    String str = lit.next();
                    tempList.add(str + 'p');
                    tempList.add(str + 'q');
                    tempList.add(str + 'r');
                    tempList.add(str + 's');
                }
            }else if(digits.charAt(i)=='8'){
                while (lit.hasNext()) {
                    String str = lit.next();
                    tempList.add(str + 't');
                    tempList.add(str + 'u');
                    tempList.add(str + 'v');
                }
            }else if(digits.charAt(i)=='9'){
                while (lit.hasNext()) {
                    String str = lit.next();
                    tempList.add(str + 'w');
                    tempList.add(str + 'x');
                    tempList.add(str + 'y');
                    tempList.add(str + 'z');
                }
            }
            result= tempList;

        }
        return result;
    }
    public static void main(String[] args) {
        String digits ="23";
        System.out.println(letterCombinations(digits));
    }
}
